<template>
  <el-cascader
    size="mini"
    :value="value"
    separator="-"
    :options="depts"
    :props="defaultProps"
    @change="handleChange"
  />
</template>

<script>
import { getDepartmentsAPI } from '@/api/department'
import { transListToTreeData } from '@/utils'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      depts: [],
      defaultProps: {
        value: 'id',
        label: 'name'
      }
    }
  },
  created() {
    this.getDepartmentList()
  },
  methods: {
    handleChange(currentNode) {
      // console.log(currentNode[currentNode.length - 1])
      this.$emit('input', currentNode[currentNode.length - 1])
    },
    async getDepartmentList() {
      this.depts = transListToTreeData(await getDepartmentsAPI())
    }
  }
}
</script>

<style>

</style>
